﻿// Copyright (c) Inossem. All rights reserved.
// Licensed under the LGPL-3.0 license. See LICENSE file in the project root for full license information.
using DWF.Studio.Custom;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DWF.Studio.Project
{
    /// <summary>
    /// 工程信息节点
    /// </summary>
    internal class ProjectInfo : ProjectNode
    {
        /// <summary>
        /// 工程id
        /// </summary>
        public string Id
        {
            set;
            get;
        }

        /// <summary>
        /// 描述信息
        /// </summary>
        public string Description
        {
            get;
            set;
        }

        /// <summary>
        /// 工程文件版本
        /// </summary>
        public string Version
        {
            set;
            get;
        }

        /// <summary>
        /// 工程版本
        /// </summary>
        public string ProjectVersion
        {
            set;
            get;
        }

        /// <summary>
        /// 目标平台
        /// </summary>
        public string TargetPlatform
        {
            set;
            get;
        }

        // <summary>
        /// 工作流语言
        /// </summary>
        public string WFLanguage
        {
            set;
            get;
        }

        /// <summary>
        /// 启动文件
        /// </summary>
        public ProjectFile StartFile
        {
            set;
            get;
        }

        private static readonly Uri _fileIcon = new Uri("..\\Resources\\Treeview\\project.png", UriKind.Relative);

        public ProjectInfo()
        {
            this.IconLoc = _fileIcon;
            this.NodeType = EProjectNodeType.Project;
            this.Children = new ObservableCollection<ProjectNode>();
            this.IsSelf = true;
        }

        public override ObservableCollection<ProjectNode> Children
        {
            get;
            set;
        }

        /// <summary>
        /// 工程信息转换为工程文件详情
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public ProjectDetail ConvertToDetail()
        {
            var detail = new ProjectDetail()
            {
                id = this.Id,
                name = this.Name,
                description = this.Description,
                ver = this.Version,
                platform = this.TargetPlatform,
                reversion = this.ProjectVersion,
                start = this.StartFile.Name,
                wflanguage = this.WFLanguage
            };

            foreach (var folder in this.Children)
            {
                if (folder.NodeType == EProjectNodeType.Dependencies)
                {
                    foreach (var nodefile in folder.Children)
                    {

                        detail.dependency.Add(nodefile.FullName);
                    }
                }
                else if (folder.NodeType == EProjectNodeType.Folder)
                {
                    if (folder.DisplayName == StaticResource.ProjectSelfFile)
                    {
                        foreach (var nodefile in folder.Children)
                        {
                            detail.file.Add(nodefile.DisplayName);
                        }
                    }
                    else if (folder.DisplayName == StaticResource.ProjectSelfLibs)
                    {
                        foreach (var nodefile in folder.Children)
                        {
                            detail.libs.Add(nodefile.DisplayName);
                        }
                    }
                    else if (folder.DisplayName == StaticResource.ProjectSelfImages)
                    {
                        foreach (var nodefile in folder.Children)
                        {
                            detail.images.Add(nodefile.DisplayName);
                        }
                    }
                    else if (folder.DisplayName == StaticResource.ProjectSelfRes)
                    {
                        foreach (var nodefile in folder.Children)
                        {
                            detail.res.Add(nodefile.DisplayName);
                        }
                    }
                }
            }

            return detail;
        }
    }
}
